package com.pudu.myformat;

import android.util.Log;

/**
 * Created by Cyc on 2016/8/18 0018.
 * 用于在界面显示数据的时候将数据统一格式化输出。保留相同的位数
 */
public class MyFormat {

    public String fixString(int setLength,String string) {

        int length = string.length();
        if (length < setLength) {
            for(int i=0;i<setLength-length;i++) {
                string = "\t"+string;
            }
        }
        Log.i("SensersFormat","fixString:"+string);

        return string;
    }

    public String singleString(double num) {
        String string;

        string = fixString(7,String.format("%.3f", num));

        return string;
    }

    public String singleString(int num) {
        String string;

        string = fixString(6,String.format("%d", num));

        return string;
    }

    public String singleString(short num) {
        String string;

        string = fixString(6,String.format("%d", num));

        return string;
    }


    public String arrayString(double[] num) {
        String string = "";

        for(int i=0; i<num.length; i++) {
            string = string + fixString(7,String.format("%.3f\n",num[i]));
        }

        return string;
    }

    public String arrayString(int[] num) {
        String string = "";

        for(int i=0; i<num.length; i++) {
            string = string + fixString(6,String.format("%d\n",num[i]));
        }

        return string;
    }

    public String arrayString(short[] num) {
        String string = "";

        for(int i=0; i<num.length; i++) {
            string = string + fixString(6,String.format("%d\n",num[i]));
        }

        Log.i("SensersFormat",string);
        return string;
    }

    public String arrayString(String numName,int[] num) {
        String string = "";

        for(int i=0; i<num.length; i++) {
            string = string + numName + String.format("[%d]:",i)+fixString(6,String.format("%d\n",num[i]));
        }

        return string;
    }

    public String arrayString(String numName,double[] num) {
        String string = "";

        for(int i=0; i<num.length; i++) {
            string = string + numName + String.format("[%d]:",i)+fixString(7,String.format("%.3f\n",num[i]));
        }

        return string;
    }

    public String arrayString(String numName,short[] num) {
        String string = "";

        for(int i=0; i<num.length; i++) {
            string = string + numName + String.format("[%d]:",i)+fixString(6,String.format("%d\n",num[i]));
        }

        return string;
    }


}
